package com.cupk.mapper;

import com.cupk.pojo.Banner;
import org.apache.ibatis.annotations.*;

import java.time.LocalDateTime;
import java.util.List;

@Mapper
public interface BannerMapper {

    @Insert("insert into banner(title,image,priority,start_time,end_time) values (#{title},#{image},#{priority},#{startTime},#{endTime})")
    void addBanner(Banner banner);

    @Select("select * from banner order by priority asc")
    List<Banner> getBannerList();

    @Select("select * from banner where start_time<= #{nowTime} and end_time >= #{nowTime} order by priority asc")
    List<Banner> getEffectiveList(LocalDateTime nowTime);

    @Update("update banner set title = #{title}, image = #{image}, priority = #{priority}, start_time = #{startTime}, end_time = #{endTime} where id = #{id}")
    void updateBanner(Banner banner);

    @Delete("delete from banner where id = #{bannerId}")
    void deleteBanner(Integer bannerId);
}
